package com.sunny.design.singleton.lazy;

/**
 * 懒汉式单例之内部类
 *
 * @author Sunny
 * @date 2019/12/29 15:52
 */
public class LazyInnerClassSingleton {
    private LazyInnerClassSingleton(){}

    /**
     * 这种方法是利用内部类的加载机制, 只有在外部类调用到内部类时,才会进行实例化
     *
     * 好处就是性能更高,没有用到锁
     *
     */
    public static LazyInnerClassSingleton getInstance() {
        return InnerClass.INSTANCE;
    }

    private static class InnerClass {
        private static final LazyInnerClassSingleton INSTANCE = new LazyInnerClassSingleton();
    }
}
